//注册校验
function initLoginValidate() {
	$.formValidator.initConfig({
		formid : "regist_form",
		onerror : function(msg) {
			alert(msg)
		}
	});
	$("#regist_email").formValidator({
		tipid : "regist_emailTip",
		onShow : " ",
		onFocus : " ",
		onCorrect : "　 "
	}).regexValidator({
		regExp : regexEnum['email'],
		onError : "邮箱地址不正确"
	}).functionValidator({
		fun : function(val, elem) {
			val = $.trim(val);
			if(val == ""){
				return "请填写邮箱地址";
			}
			// 检测邮箱能否用来注册
			var params = {"loginName":val};
			var error = "";
			doAsyncAjax("/userAjax/checkLoginName.action", params, function(ajaxResult) {
				if (!ajaxResult.OK) {
					error = ajaxResult.message
				} 
			});
			if(error != ""){
				return error;
			}else{
				$("#user_email").val(val);
			}
		}
	}).focus(function(){
		$(this).triggerHandler('blur');
	});
	$("#regist_nickname").formValidator({
		tipid : "regist_nicknameTip",
		onShow : "",
		onFocus : " ",
		onCorrect : "　 "
	}).inputValidator({
		min : 4,
		max : 20,
		onError : "昵称最少4、最多20个字符"
	}).regexValidator({
		regExp : "^[a-zA-Z_0-9\u4E00-\u9FA5\s\\(\\)\\.]+$",
		onError : "昵称格式不合法：中英文、数字、下划线"
	}).functionValidator({
		fun : function(val, elem) {
			val = $.trim(val);
			if (val == "") {
				return "请填入昵称";
			}
			// 检测昵称用来注册
			var params = {"nickName":val};
			var error = "";
			doAsyncAjax("/userAjax/checkNickname.action", params, function(ajaxResult) {
				if (!ajaxResult.OK) {
					error = ajaxResult.message
				} 
			});
			if(error != ""){
				return error;
			}
		}
	});
	$("#regist_pwd1").formValidator({
		tipid : "regist_pwd1Tip",
		onShow : "",
		onFocus : " ",
		onCorrect : "　 "
	}).inputValidator({
		min:6,
		max:20,
		empty:{leftEmpty:false,rightEmpty:false,emptyError:"密码两边不能有空格"},
		onError:"密码长度：6-20位"
	}).regexValidator({
		regExp : "^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,20}$",
		onError : "密码不合法：6-20个字母、数字或符号"
	});
	$("#regist_pwd2").formValidator({
		tipid : "regist_pwd2Tip",
		onShow : "",
		onFocus : " ",
		onCorrect : "　 "
	}).inputValidator({
		min:6,
		max:20,
		empty:{leftEmpty:false,rightEmpty:false,emptyError:"密码两边不能有空格"},
		onError:"密码长度：6-20位"
	}).compareValidator({
		desID:"regist_pwd1",
		operateor:"=",
		onError:"2次密码不一致,请确认"
	});
}
// 登陆页登陆
function pageLogin() {
	$(".iserror").hide();
	var loginName = $.trim($("#loginName").val());
	var loginPwd = $.trim($("#loginPassword").val());
	if (loginName == "" || loginName == "用户名") {
		$("#loginNameTip").text("请输入用户名");
		$(".err_name").show();
		return false;
	} else {
		$(".err_name").hide();
	}
	if (loginPwd == "") {
		$("#loginPasswordTip").text("请输入密码");
		$(".err_pass").show();
		return false;
	} else {
		$(".err_pass").hide();
	}
	var params = {
		"loginName" : loginName,
		"loginPwd" : loginPwd
	};
	var url = "/userAjax/login.action";
	doAsyncAjax(url, params, function(ajaxResult) {
		if (ajaxResult.OK) {
			location = "../user/home.action";
		} else {
			if(ajaxResult.message == '用户未激活，请激活!'){
				location = "/toJihuo.action?myEmail="+ajaxResult.resultMap.loginEmail;
			}else{
				$(".err_name").hide();
				$(".err_pass").hide();
				$(".iserror").show();
			}
		}
	});
}
// 登陆
function login() {
	var loginName = $.trim($("#logName").val());
	var loginPwd = $.trim($("#logPwd").val());
	if (loginName == "" || loginPwd == "") {
		alertTipDown("用户名或密码不能为空", "cuo");
		alertTipUp();
		return false;
	}
	var params = {
		"loginName" : loginName,
		"loginPwd" : loginPwd
	};
	var url = "/userAjax/login.action";
	doAsyncAjax(url, params, function(ajaxResult) {
		if (ajaxResult.OK) {
			//alert(window.location.href);
			window.location.reload(); 
		} else {
			if(ajaxResult.message == '用户未激活，请激活!'){
				location = "/toJihuo.action?myEmail="+ajaxResult.resultMap.loginEmail;
			}else{
				alertTipDown(ajaxResult.message, "cuo");
				alertTipUp();
			}
		}
	});
}
// 退出
function logout() {
	var url = "../userAjax/logout.action";
	var params = {};
	doAjaxHtml(url, params, function() {
		location = "../user/home.action";
	});
}
// 注册
function regist() {
	if(!$.formValidator.pageIsValid('1')){
    	return false;
    }
	//获取参数
//	var rEmail = $.trim($("#regist_email").val());
//	var rNick = $.trim($("#regist_nickname").val());
//	var rPwd = $.trim($("#regist_pwd1").val());
//	var rSex = $('input:radio:checked').val();
//	var params = {
//		"user.loginName" : rEmail,
//		"user.nickname" : rNick,
//		"user.loginPwd" : rPwd,
//		"user.email" : rEmail,
//		"user.gender" : rSex
//	};
	$("#regist_form").submit();
//	String url = "/userAjax/registUser.action";
//	doAjax(url, params, function(ajaxResult) {
//		if (ajaxResult.OK) {
//			window.location.href = "/toJihuo.action";
//		} else {
//			//alert(ajaxResult.message);
//		}
//	});
}
// 等了注册切换
function toggleRegister() {
	// $('#toRegistPop').click(function(){
	// $('#pop_login h3 a').trigger('click');
	// $('#toRegist').trigger('click');
	// });
	$('#toLoginPop').click(function() {
		$('#pop_regist h3 a').trigger('click');
		$('#toLogin').trigger('click');
	});
}